﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <link href="../Plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" />
    <link href="../zui/lib/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../zui/css/font-awesome.min.css" rel="stylesheet" />
    <link href="../zui/css/zui.min.css" rel="stylesheet" />
    <link href="../zui/lib/layer/skin/default/layer.css" rel="stylesheet" />
    <link href="../Plugins/sweetalert/sweetalert.css" rel="stylesheet" />
    <link href="../zui/lib/swiper/css/swiper.min.css" rel="stylesheet" />
    <link href="../zui/css/app.css" rel="stylesheet" />
    <title></title>
    <style type="text/css">
        .form-control {
            font-size: 16px !important;
            height: 40px;
            line-height: 28px;
        }

        .form-group {
            font-size: 20px !important;
        }

        .btn {
            height: 50px;
            font-size: 18px !important;
        }

        body {
            font-size: 16px !important;
        }

        .wizard .content {
            min-height: 650px;
            width: 580px;
            margin: 0px !important;
        }

        .wizard > .content > .body {
            width: 100% !important;
            height: 100% !important;
            border-color: #d0c8c8 !important;
            border-width: 1px;
            border-style: solid;
        }

        .sweetAlert{
            margin-top: -300px !important;
        }
    </style>
</head>
<body>
    <div class="container" style="padding-left:0px !important;max-width:870px!important; width:870px">
        <div style="background-color:#eee;height:350px; overflow-y:scroll;border-radius:5px;padding:15px">
            <h1 style="margin-top:5px" id="title">编辑用户信息</h1>
            <hr style="border-color:#d0c8c8" />
            <form class="form-horizontal" style="width:350px;padding-left:5px">
                <fieldset>

                    <div class="form-group">
                        <label for="exampleInputAccount4" class="col-xs-4">姓名</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control numkeyboard" value="" id="realName" placeholder="">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="exampleInputAccount4" class="col-xs-4">账号</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control numkeyboard" value="" id="userName" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputAccount4" class="col-xs-4">性别</label>
                        <div class="col-xs-8">
                            <label class="radio-inline">
                                <input type="radio" checked="checked" value="1" name="userSex"> 男
                            </label>
                            <label class="radio-inline">
                                <input type="radio" value="0" name="userSex"> 女
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputAccount4" class="col-xs-4">电话</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control numkeyboard" value="" id="userPhone" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputAccount4" class="col-xs-4">角色</label>
                        <div class="col-xs-8">
                            <label class="radio-inline">
                                <input type="radio" checked="checked" value="2" name="userRole"> 普通用户
                            </label>
                            <label class="radio-inline">
                                <input type="radio" value="1" name="userRole"> 管理员
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword4" class="col-xs-4">备注信息</label>
                        <div class="col-xs-8">
                            <textarea class="form-control numkeyboard" id="remark" rows="3"></textarea>
                        </div>
                    </div>
                </fieldset>
            </form>
            <div class="shiyan-footer" style="position:fixed; bottom:90px;margin-bottom: 8px">
                <button style="float:left;margin-right:5px" class="btn btn-default btn-lg back-btn" type="button">返回</button>
                <button style="float:right" class="btn btn-primary btn-lg" id="saveBtn" type="button">保存</button>
                <button style="float:right;margin-right:5px" class="btn btn-danger btn-lg sxt-btn" id="deleteUserBtn" type="button">删除</button>
                <button style="float:right;margin-right:5px" class="btn btn-default btn-lg sxt-btn" id="resetPwdBtn" type="button">重置密码</button>

            </div>
        </div>
    </div>
    <script src="../zui/lib/jquery/jquery.js"></script>
    <script src="../Plugins/jquery-ui/jquery-ui.min.js"></script>
    <script src="../zui/js/zui.min.js"></script>
    <script src="../zui/lib/bootstrap/js/bootstrap.min.js"></script>
    <script src="../zui/lib/layer/layer.js"></script>
    <script src="../Plugins/sweetalert/sweetalert.min.js"></script>
    <script src="../zui/lib/swiper/js/swiper.min.js"></script>
    <script src="../zui/js/utils.js"></script>
    <script src="../zui/js/app.js"></script>
    <script type="text/javascript">
        $(function () {
            //获取用户ID
            var userId = getQueryString("userId");
            $("#title").text((userId == 0 ? "新增" : "编辑") + '用户信息');
            if (userId != 0) {
                ////获取用户信息
                AjaxGet("正在获取用户数据...", "getUserInfo",
                    {
                        userId: userId
                    }, function (res) {
                        var userInfo = JSON.parse(res).data;
                        $("#realName").val(userInfo.real_name);
                        $("#userName").val(userInfo.user_name);
                        $("#userPhone").val(userInfo.user_phone)
                        $(":radio[name='userRole'][value='" + userInfo.user_role + "']").prop("checked", "checked");
                        $(":radio[name='userSex'][value='" + userInfo.user_sex + "']").prop("checked", "checked");
                        $('#remark').val(userInfo.remark)
                    });
                //var userInfo = JSON.parse(top.dataOpera.getUserInfo(userId)).data;
                //$("#realName").val(userInfo.real_name);
                //$("#userName").val(userInfo.user_name);
                //$("#userPhone").val(userInfo.user_phone)
                //$(":radio[name='userRole'][value='" + userInfo.user_role + "']").prop("checked", "checked");
                //$(":radio[name='userSex'][value='" + userInfo.user_sex + "']").prop("checked", "checked");

            }
            else {
                $("#deleteUserBtn").hide();
                $("#resetPwdBtn").hide();
            }
            //保存用户信息
            $("#saveBtn").click(function () {
                var realName = $("#realName").val();
                var userName = $("#userName").val();
                var userPwd = $("#userPwd").val();
                var userPhone = $("#userPhone").val();
                var userRole = $('input:radio[name="userRole"]:checked').val();
                var userSex = $('input:radio[name="userSex"]:checked').val();
                var remark = $("#remark").val();
                if (realName.trim() == "") {
                    swal({
                        'title': '提示',
                        'text': '用户姓名不能为空！',
                        'type': 'warning',
                        customClass: 'sweetAlert',
                    });

                    return;
                }
                if (userName.trim() == "") {
                    swal({
                        'title': '提示',
                        'text': '用户账号不能为空！',
                        'type': 'warning',
                        customClass: 'sweetAlert',

                    });

                    return;
                }
                AjaxGet("正在获取用户数据...", "saveUser",
                    {
                        userId: userId,
                        userName: userName,
                        realName: realName,
                        userSex: parseInt(userSex),
                        userRole: parseInt(userRole),
                        userPhone: userPhone,
                        remark: remark
                    }, function (res) {
                        var obj = JSON.parse(res);
                        if (obj.status == 1) {
                            new top.$.zui.Messager('保存用户信息成功！', {
                                close: false,
                                type: 'success'
                            }).show();
                            location.href = "UserManage.html";

                        }
                    });

            })
            //删除用户事件
            $("#deleteUserBtn").click(function () {
                swal({
                    title: "您确定要删除本用户么？",
                    text: "删除后将不可再恢复！",
                    type: "warning",
                    customClass: 'sweetAlert',
                    animation: false,
                    showCancelButton: true,
                    cancelButtonText: "取消",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确认",
                    closeOnConfirm: false
                }, function () {
                    AjaxGet("正在删除用户信息...", "deleteUser",
                        {
                            userId: userId
                        }, function (res) {
                            new top.$.zui.Messager('删除用户成功！', {
                                close: false,
                                type: 'success'
                            }).show();
                            location.href = "UserManage.html";
                        });
                });
            })
            //重置用户密码事件
            $("#resetPwdBtn").click(function () {
                swal({
                    title: "您确定要重置本用户密码么？",
                    text: "密码将被重置为“000000”！",
                    type: "warning",
                    animation: false,
                    customClass: 'sweetAlert',
                    showCancelButton: true,
                    cancelButtonText: "取消",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确认",
                    closeOnConfirm: false
                }, function () {
                    AjaxGet("正在修改用户密码...", "updateUserPassword",
                        {
                            userId: userId,
                            userPwd: "000000"
                        }, function (res) {
                            new top.$.zui.Messager('用户密码重置成功！', {
                                close: false,
                                type: 'success'
                            }).show();
                            location.href = "UserManage.html";
                        });

                });
            })
            //返回用户列表页
            $(".back-btn").click(function () {
                location.href = "UserManage.html";
            })
        })
    </script>
</body>
</html>
